package cn.tedu.spring.dibase;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

/**
 * 依赖注入
 *
 * Dao: 数据访问层
 */
@Component
//@Repository
//@Service
//@Controller
public class UserDao {
    /*
        依赖注入DI 给属性赋值
        给简单类型或基本类型属性赋值 如字符串,数值等类型 对象或接口等不行
     */
    @Value("jdbc:mysql://localhost:3306/tedu")
    private String url;
    //@Value("root")
    private String username;
    @Value("root")
    private String password;
    @Value("root")//该注释只能添加到set方法或简单类型属性上进行赋值
    public void setUsername(String username) {
        this.username = username;
    }

    @Override
    public String toString() {
        return "UserDao{" +
                "url='" + url + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
